#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import os
from utils import read_config

result_path = os.path.join(read_config.data_path, 'result', '突破均线')


# 获取一个链接按钮
def get_button_href(url, button_name):
    return '<a href="' + url + '"> <button>' + button_name + '</button> </a>'


# 获取一个按钮
def get_button(name):
    print('')


# 获取一个展示链表
def get_form_list(menu_name, name_dict):
    form_list = '<ul class="nav nav-pills nav-stacked custom-nav">'
    form_list += '<li><span>' + menu_name + '</span>'
    for key in name_dict.keys():
        value = name_dict[key]
        if isinstance(value, dict):
            form_list += get_form_list(key, value)
        elif isinstance(value, list):
            form_list += '<ul class="sub-menu-list"><span>' + key + '</span>'
            for value1 in value:
                form_list += '<li><a href="index.html">' + value1 + '</a></li>'
            form_list += '</ul>'
        else:
            form_list += '<li class="active"><a href="index.html">' + key + '</a></li>'
    form_list += '</li>'
    form_list += '</ul>'
    return form_list


# 获取一个可跳转链表
def get_form_list_actual(menu_name, name_dict):
    form_list = '<ul class="nav nav-pills nav-stacked custom-nav">'
    form_list += '<li><span>' + menu_name + '</span>'
    for key in name_dict.keys():
        value = name_dict[key]
        if isinstance(value, dict):
            form_list += get_form_list_actual(key, value)
        elif isinstance(value, list):
            form_list += '<ul class="sub-menu-list"><span>' + key + '</span>'
            for value1 in value:
                if isinstance(value1, list):
                    if len(value1) == 2:
                        form_list += '<li><a href="' + value1[1] + '">' + value1[0] + '</a></li>'
                    if len(value1) == 3:
                        form_list += '<li>'
                        form_list += '<div id="main" style="width:600px;" >'
                        form_list += '   <div id="left" style="width:100px;float:left;" >'
                        form_list += '   <a href="' + value1[1] + '">' + value1[0] + '</a></div>'
                        form_list += '   <div id="right" style="width:500px;float:left;" >' + value1[2] + '</div>'
                        form_list += '</div>'
                        form_list += '</li>'
                elif isinstance(value1, dict):
                    if 'url' in value1.keys():
                        form_list += '<li><a href="' + value1['url'] + '">' + value1['name'] + '</a></li>'
                else:
                    form_list += '<li>' + value1 + '</li>'
            form_list += '</ul>'
        else:
            form_list += '<li>' + key + '</li>'
    form_list += '</li>'
    form_list += '</ul>'
    return form_list


# 获取一个展示链表含有按钮
def get_form_list_has_button(menu_name, name_dict):
    form_list = '<ul class="nav nav-pills nav-stacked custom-nav">'
    form_list += '<li><span>' + menu_name + '</span>'
    for key in name_dict.keys():
        value = name_dict[key]
        if 'url' in value.keys():
            form_list += '<ul class="sub-menu-list"><text>' + value['title'] + '</text>'
            form_list += '<li><a href="' + value['url'] + '"> '
            form_list += '<button>' + value['button'] + '</button> </a></li>'
            form_list += '</ul>'
        else:
            form_list += get_form_list_has_button(key, value)
    form_list += '</li>'
    form_list += '</ul>'
    return form_list


# 获取一个标题
def get_title(name):
    title = '<h><font size="4" align="center" style="font-family:Microsoft YaHei" color="black">' + name + '</font></h>'
    return title


# 获取一个标题
def get_a_text(name):
    text = '<text>' + name + '</text>'
    return text


# 获取一个表格
def get_form(action, method, form_name, row_name_dict, submit_name):
    form = ' <form action="' + action + '" method="' + method + '" name="' + form_name + '">'
    for key in row_name_dict:
        form += key + ': <input type="text" name="' + row_name_dict[key] + '"><br>'
    form += '    <input type="submit" value="' + submit_name + '">'
    form += ' </form>'
    return form


# 获取一个表格
def get_form_has_value(action, method, form_name, row_dict, submit_name):
    form = ' <form action="' + action + '" method="' + method + '" name="' + form_name + '">'
    for key in row_dict:
        value = row_dict[key]
        if isinstance(value, list):
            if len(value) == 2:
                form += key + ': <input type="text" name="' + value[0] + '" value="' + value[1] + '"> <br>'
            elif len(value) == 1:
                form += key + ': <input type="text" name="' + value[0] + '"> <br>'
        elif isinstance(value, dict):
            form += key + ': <input type="text" name="' + value['name'] + '" value="' + value['value'] + '"> <br>'
        else:
            form += key + ': <input type="text" name="' + value + '"> <br>'
    form += '    <input type="submit" value="' + submit_name + '">'
    form += ' </form>'
    return form


# 获取一个表格
# content_arr : 二维数组
def get_a_table(content_arr):
    table = '<table border="1">'
    for row in content_arr:
        table += '<tr>'
        for cell in row:
            table += '<th>' + str(cell) + '</th>'
        table += '</tr>'
    table += '</table>'
    return table


if __name__ == "__main__":
    print('')
